﻿using GIMS.Def.Arguments;
using GIMS.Def.Operators;
using GIMS.Def.Settings;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using System.ComponentModel;

namespace GIMS.Def.Test
{
    /// <summary>
    ///This is a test class for ResizeOperatorTest and is intended
    ///to contain all ResizeOperatorTest Unit Tests
    ///</summary>
    [TestClass()]
    public class ResizeOperatorTest
    {
        /// <summary>
        /// Reset GlobalSettings
        /// </summary>
        [TestInitialize()]
        public void MyTestInitialize()
        {
            GlobalSettings_Accessor.instance = null;
        }

        /// <summary>
        ///A test for CreateScriptPart - resize with percent argument
        ///</summary>
        [TestMethod()]
        public void CreateScriptPartTest1()
        {
            ResizeOperator_Accessor target = new ResizeOperator_Accessor(); 
            GeometryArgument arg = (GeometryArgument) target.Argument;
            arg.SelectedGeometryType = GeometryType.percent;
            arg.Scale = 20;
            string actual;
            actual = target.CreateScriptPart();
            Assert.AreEqual("-resize 20%%", actual);
        }

        /// <summary>
        ///A test for CreateScriptPart - Resize with area argument
        ///</summary>
        [TestMethod()]
        public void CreateScriptPartTest2()
        {
            ResizeOperator_Accessor target = new ResizeOperator_Accessor(); 
            GeometryArgument arg = (GeometryArgument)target.Argument;
            arg.SelectedGeometryType = GeometryType.area;
            arg.Area = 555;
            string actual;
            actual = target.CreateScriptPart();
            Assert.AreEqual("-resize 555@", actual);
        }

        /// <summary>
        ///A test for CreateScriptPart - Resize with widthxheight and "more flag"
        ///</summary>
        [TestMethod()]
        public void CreateScriptPartTest3()
        {
            ResizeOperator_Accessor target = new ResizeOperator_Accessor();
            GeometryArgument arg = (GeometryArgument)target.Argument;
            arg.SelectedGeometryType = GeometryType.widthxheight;
            arg.GeometryRadio=GeometryRadio.more;
            arg.Width = 10;
            arg.Height = 20;
            string actual;
            actual = target.CreateScriptPart();
            Assert.AreEqual("-resize \"10x20>\"", actual);
        }

        /// <summary>
        ///A test for CreateScriptPart - Resize with x-percent and y-percent
        ///</summary>
        [TestMethod()]
        public void CreateScriptPartTest4()
        {
            ResizeOperator_Accessor target = new ResizeOperator_Accessor();
            GeometryArgument arg = (GeometryArgument)target.Argument;
            arg.SelectedGeometryType = GeometryType.xypercent;
            arg.ScaleX = 10;
            arg.ScaleY = 20;
            Assert.AreEqual("-resize 10%%x20%%", target.CreateScriptPart());
        }

        /// <summary>
        ///A test for the constructor - ceck that argument name and type are set
        ///</summary>
        [TestMethod()]
        public void ResizeOperatorTest1()
        {
            ResizeOperator_Accessor target = new ResizeOperator_Accessor();
            GeometryArgument arg = (GeometryArgument)target.Argument;
            arg.SelectedGeometryType = GeometryType.widthxheight;
            Assert.IsTrue(arg.Type==Flags.ArgumentType.geometry);
            Assert.IsFalse(string.IsNullOrEmpty(arg.Name));
        }

        /// <summary>
        ///A test for the changed argument event
        ///</summary>
        [TestMethod()]
        [DeploymentItem("GIMS.Def.dll")]
        public void ArgumentChangedTest()
        {
            List<string> receivedEvents = new List<string>();
            ResizeOperator target = new ResizeOperator();

            target.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                receivedEvents.Add(e.PropertyName);
            };

            ((GeometryArgument)target.Argument).Scale = 20;     //event
            ((GeometryArgument)target.Argument).SelectedGeometryType = GeometryType.percent;    //event
            Assert.AreEqual(2, receivedEvents.Count);
            Assert.AreEqual("Argument.geometry", receivedEvents[0]);
        }
    }
}
